<?php
	$numberVisitted = $this->escort_visitted_entity->countNumberVisittedOfEscortInMonth($escort->getId(),time());
	$numberVisitted = $numberVisitted ? $numberVisitted:0;
	$numberMessage = $this->visitor_contact_entity->countAllMessagesEscortReceipt($escort->getId());
	$PAYMENT_LOG = $this->payment_log_entity->getNetAmount($escort->getId());
	$LATEST_PAYMENT = $this->payment_history->getLatestPaymentHistory($escort->getId());
	
	$countUnread = $this->escort_message_thread_entity->countAllUnreadMessagesOfUser($escort->getId(),USER_TYPE_ESCORT);	
?>
<fieldset>
	<ul id="dashboard-content" class="ui-sortable form_inputs">
		<li class="" id="dashboard_visit">
			<label for="site_name"><?php echo lang('escort_be_escort_dashboard_visit_label')?></label>
			<div class="input type-text">
				<?php echo sprintf(lang('escort_be_escort_dashboard_visit_content_label'), $numberVisitted)?>
			</div>
		</li>
		<li class="" id="dashboard_position">
			<label for="site_name"><?php echo lang('escort_be_escort_dashboard_position_label')?></label>
			<div class="input type-text">
			<span class="gray"><?php echo sprintf(lang('escort_be_escort_dashboard_position_content_label'), $escort->getNumberFirstStanding());?></span>
			</div>
		</li>
		<li class="" id="dashboard_contact_data">
			<label for="site_name"><?php echo lang('escort_be_escort_dashboard_contact_data_label')?></label>
			<div class="input type-text">
				<span class="gray"><?php echo sprintf(lang('escort_be_escort_dashboard_contact_data_content_label'),$escort->getTimesPhoneDisplayed(), $numberMessage);?></span>
			</div>
		</li>
		<li class="" id="dashboard_current_services">
			<label for="site_name"><?php echo lang('escort_be_escort_dashboard_current_services_label')?></label>
			<div class="input type-text">
				<span class="gray"><?php if($PAYMENT_LOG) echo sprintf(lang('escort_be_escort_dashboard_current_services_content_label'), $PAYMENT_LOG);?></span>
				<!-- <span class="black"><a href="<?php echo site_url("admin/be_escort/edit/1#ui-tabs-4");?>"><?php echo lang('escort_be_escort_dashboard_services_change');?></a></span> -->
			</div>
		</li>
		<li class="" id="dashboard_last_payment">
			<label for="site_name"><?php echo lang('escort_be_escort_dashboard_last_payment_label')?></label>
			<div class="input type-text">
				<span class="gray"><?php if($LATEST_PAYMENT) echo $LATEST_PAYMENT->getPayment();?> &euro; <?php echo lang('escort_be_escort_dashboard_credit_card_lable');?></span>
				<?php
				if($LATEST_PAYMENT){ 
					echo language_translate('escort_be_escort_dashboard_payment_history_datetime');
					echo format_date($LATEST_PAYMENT->datetime);
				}
				?>
				<!-- <span class="black"><a href="<?php echo site_url("agent/account/payment_history");?>"><?php echo lang('descort_be_escort_ashboard_history_lable');?></a></span> -->
			</div>
		</li>
		<li class="" id="dashboard_unread_messages">
			<label for="site_name"><?php echo lang('escort_be_escort_dashboard_unread_messages_label')?></label>
			<div class="input type-text">
				<span class="gray"><?php echo sprintf(lang('escort_be_escort_dashboard_content_unread_message'), $countUnread);?></span>
			</div>
		</li>
		<!-- 
		<li class="" id="dashboard_offers">
			<label for="site_name"><?php echo lang('escort_be_escort_dashboard_offers_label')?></label>
			<div class="input type-text">
				<span class="gray"><a href="<?php echo site_url("agent/account/payment_nextmonth");?>"><?php echo lang('escort_be_escort_dashboard_offer_link_lable');?></a></span>
			</div>
		</li>
		 -->
		<li class="" id="dashboard_popular_image">
			<label for="site_name"><?php echo lang('escort_be_escort_dashboard_popular_image_label')?></label>
			<div class="input type-text">
				<?php $OBJ = $this->media_entity->getObjectOfMostPopularImage($escort->getId());?>
				<?php if($OBJ AND $OBJ->getClickedNo() > 0):?>
					<!-- 
					<span class="gray">
						<a href="javascript:void(0);" onclick="return openMostPopularImage(<?php //echo $OBJ->getId();?>);"><?php //if($OBJ) echo $OBJ->getName();?></a>
					</span>
					 -->
					<?php if($OBJ->getType() =='image'):?>
						<?php echo thumb($OBJ->getTargetFileImageTopPublic('big'),THUMB_WW,THUMB_HH);?>
					<?php else:?>
						<?php echo playvideo($OBJ->getTargetFile('video'),$OBJ->getTargetFile('avatar'),THUMB_WW,THUMB_HH);?>
					<?php endif; ?>
				<?php endif;?>
			</div>
		</li>
		<li>
			<label for="site_name">&nbsp;</label>
			<div class="input type-text">
				<div id="googlechart"></div>
			</div> 
		</li>
	</ul>
</fieldset>
<?php 
	$arrayNumberVisittedByMonth = $this->escort_visitted_entity->arrayVisittedOfEscortAllTime($escort->getId());
	$arrayJS =  array();
	if($arrayNumberVisittedByMonth){
		foreach($arrayNumberVisittedByMonth as $key => $val){
			list($from , $to) = explode('_',$key);
			$arrayJS[] = array( date('m/Y',$from), intval($val));
		}
	}
	$json = json_encode($arrayJS);
?>

<script type="text/javascript">
	//google.load("visualization", "1", {packages:["corechart"]});
	function drawVisualization() {
		  var data = new google.visualization.DataTable();
		  data.addColumn('string', '<?php echo language_translate('dashboard_lable_month_chart');?>');
		  data.addColumn('number', '<?php echo language_translate('dashboard_lable_visitted_time');?>');
		
		  data.addRows(<?php echo $json;?>);
		  var ac = new google.visualization.ColumnChart(document.getElementById('googlechart'));
		  ac.draw(data, {
			title : '<?php echo language_translate('dashboard_lable_chart_title');?>',
			isStacked: false,
			width: 600,
			height: 400,
			vAxis: {title: "<?php echo language_translate('dashboard_lable_visitted_time');?>" },
			hAxis: {title: "<?php echo language_translate('dashboard_lable_month_chart');?>", viewWindow:{max:10},},
			lineWidth:0,
			
		  });
	}
	
	$(document).ready(function(){drawVisualization()});
	
	function openMostPopularImage(media_id){
		$('#greyDiv').removeClass('hidden');
		$.get(BASE_URI+'escorts/async/getDialog_openMostPopularImage',{media_id:media_id},function(res){
			$('#hiddenElement').html(res);
			$('#hiddenElement').dialog(
				{
					 width: 650,
					 height:350 ,
					 draggable: false,
					 beforeClose: function(event, ui) { 
						$('#greyDiv').addClass('hidden');
					 },
					 close: function(event, ui) { 
					},
					 title: '<?php echo language_translate('dashboard_lable_popular_image');?>' 
				}
			);
			$('.ui-dialog').center();
		});
	}
</script>